package com.gulimall.product.conf;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author coder_ccy
 * @date 2022/3/31 14:11
 */

@Configuration
public class MyThreadPoolExecuter {


    //写代码不能硬编码
    @Bean
    public ThreadPoolExecutor threadPoolExecutor(ThreadPoolConfig config){
        return new ThreadPoolExecutor(
                config.getCoreSize(),
                config.getMaxSize(),
                config.getKeepAliveTime(),
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(config.getQueueLength()),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );


    }
}
